********************************************************************************
** Replication code ************************************************************
** The EU Commission: Supplying Enforcement & **********************************
** Demanding Compliance ********************************************************
********************************************************************************

clear all
use "eup_replication_data_10_23.dta", clear

*** create controls ***
global eu_controls log_pop log_dp EU_trade log_eu gov complaints
describe $eu_controls

*** Figure A1 online appendix ***
set scheme plottig
graph twoway line total_inf formal_count reason_count court_count year1, by(country_name, ///	
					note("")) ///
					xtitle(Year) ///
					ytitle(Infringement Count)

********************************************************************************
** xtpoisson *******************************************************************
********************************************************************************

eststo clear

eststo : xtpoisson total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust)
est store m150

eststo : xtpoisson formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) 
est store m151

eststo : xtpoisson reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) 
est store m152

eststo : xtpoisson court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) 
est store m153

*** Table A1 in online appendix ***
esttab m150 m151 m152 m153, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers nogaps ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinion" "Referrals to ECJ") /// 
	label title("Conditional fixed effects Poisson model with cluster robust standard errors and controls (country-level fixed effects) 2005-2020") ///
		order($eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log)
		
*** Figure 3 ***
set scheme plotplain
coefplot m150 m151 m152 m153, ///
sort keep(mig_crisis eurozone crimea_crisis rule_crisis brexit_crisis covid_crisis)  ///
xline(0) plotlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") xlabel(-20(5)5) xscale(range(-20 5))

*** Figure 5 ***
set scheme plotplain
coefplot m150 m151 m152 m153, ///
sort keep(par_log wtmean_image)  ///
xline(0) plotlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") xlabel(-2 2) xscale(range(-2 2))

*** Figure 7 ***
set scheme plotplain
coefplot m150 m151 m152 m153, ///
sort keep($eu_controls)  ///
xline(0) plotlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") xlabel(-7 3) xscale(range(-7 3))

********************************************************************************
** IRR *************************************************************************
********************************************************************************

eststo clear

eststo : xtpoisson total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) irr
est store m35

eststo : xtpoisson formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) irr
est store m36

eststo : xtpoisson reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) irr
est store m37

eststo : xtpoisson court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(robust) irr
est store m38

*** Table A2 in online appendix ***
esttab m35 m36 m37 m38, ///
	eform ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers nogaps ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinion" "Referrals to ECJ") /// 
	varlabel(mig_crisis "Migration crisis" crimea_crisis "Crimea crisis" ///
	brexit_crisis "Brexit crisis" eurozone "Eurozone crisis" wtmean_image "EU Image" //////
	covid_crisis "Covid crisis" rule_crisis "Rule of law crisis" par_log "Parliament questions" ///
	log_pop "Log of population" log_dp "Log GDP" EU_trade "Intra-EU trade" log_eu "Log EU years" ///
	gov "Effectiveness" complaints "Complaints")
	order($eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log)
	
********************************************************************************
** GLM  ************************************************************************
********************************************************************************

eststo clear

glm total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log i.state, family(poisson) link(log) vce(cluster state)
est store m200

glm formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log i.state, family(poisson) link(log) vce(cluster state)
est store m201
	
glm reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log i.state, family(poisson) link(log) vce(cluster state)
est store m202

glm court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log i.state, family(poisson) link(log) vce(cluster state)
est store m203

*** Table A3 online appendix ***
esttab m200 m201 m202 m203, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers nogaps  ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") ///
	varlabel(_cons "Constant" mig_crisis "Migration crisis" crimea_crisis "Crimea crisis" ///
	brexit_crisis "Brexit crisis" eurozone "Eurozone crisis" wtmean_image "EU image" par_log "Parliament questions" ///
	covid_crisis "Covid crisis" rule_crisis "Rule of law crisis" log_eu "Log of EU years" ///
	log_dp "Log of GDP" log_pop "Log of population" EU_trade "Intra-EU trade" ///
	gov "Effectiveness" complaints "Noncompliance") ///
	keep($eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log) ///
	order($eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log)

*** Table A4 online appendix ***
esttab m200 m201 m202 m203, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers nogaps onecell alignment(r) ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") ///
	label title("Generalized linear model: Country dummies 2005-2020") ///
	drop(rule_crisis brexit_crisis covid_crisis mig_crisis crimea_crisis eurozone wtmean_image par_log $eu_controls)


********************************************************************************
** Marginal effects  ***********************************************************
********************************************************************************
	
glm total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log i.state, family(poisson) link(log) vce(cluster state)
est store m200

*** Figure 4 ***
set scheme plotplain
margins, at(eurozone=(0 .4)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n1.gph, replace

margins, at(mig_crisis=(0 .3)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n2.gph, replace

margins, at(crimea_crisis=(0 .3)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n3.gph, replace

margins, at(brexit_crisis=(0 .2)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n4.gph, replace

margins, at(covid_crisis=(0 .4)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n5.gph, replace

margins, at(rule_crisis=(0 .2)) 
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n6.gph, replace

graph combine n1.gph n2.gph n3.gph n4.gph n5.gph n6.gph, ycommon

*** Figure 6 ***
set scheme plotplain
margins, at(wtmean_image=(2 4))
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n7.gph, replace

margins, at(par_log=(8 10))
marginsplot, ytitle("Predicted # of infringements") title("")
graph save n8.gph, replace

graph combine n7.gph n8.gph, ycommon

********************************************************************************
** Robustness ******************************************************************
** Non-transformed parliament questions ****************************************
********************************************************************************

lab var question_total "Total questions"

eststo : xtpoisson total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image question_total, fe vce(robust)
est store m100

eststo : xtpoisson formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image question_total, fe vce(robust)
est store m101

eststo : xtpoisson reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image question_total, fe vce(robust)
est store m102

eststo : xtpoisson court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image question_total, fe vce(robust)
est store m103

*** Table A5 online appendix ***
esttab m100 m101 m102 m103, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers nogaps ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinion" "Referrals to ECJ") /// 
	label title("Robustness: conditional fixed effects Poisson model with controls and non-transformed parliament questions 2005-2020") ///
		keep(rule_crisis brexit_crisis covid_crisis mig_crisis crimea_crisis eurozone wtmean_image question_total $eu_controls) ///
		order(rule_crisis brexit_crisis covid_crisis mig_crisis crimea_crisis eurozone $eu_controls wtmean_image question_total)
	
********************************************************************************
** Robustness ******************************************************************
** Conditional fixed effects negative binomial *********************************
********************************************************************************

eststo clear

eststo : xtnbreg total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe
est store m10

eststo: xtnbreg formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe 
est store m11

eststo: xtnbreg reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe 
est store m12

eststo: xtnbreg court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe 
est store m13

*** Table A6 online appendix ***
esttab m10 m11 m12 m13, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinion" "Referrals to ECJ") /// 
	label title("Robustness: conditional fixed effects negative binomial model with controls (country-level fixed effects) 2005-2020") ///
		order(rule_crisis brexit_crisis covid_crisis mig_crisis crimea_crisis eurozone $eu_controls _cons) ///
	varlabel(_cons "Constant")

*** With bootstrap errors ***

eststo clear

set seed 150
eststo: xtnbreg total_inf $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(bootstrap)
est store m15

set seed 160
eststo: xtnbreg formal_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(bootstrap)
est store m16

set seed 170
eststo: xtnbreg reason_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(bootstrap)
est store m17

set seed 180
eststo: xtnbreg court_count $eu_controls eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, fe vce(bootstrap)
est store m18

*** Table A7 online appendix ***
esttab m15 m16 m17 m18, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Formal letters" "Reasoned opinion" "Referrals to ECJ") /// 
	label title("Robustness: conditional fixed effects negative binomial model with controls (country-level fixed effects) \& boot strapped standard errors 2005-2020") ///
		order(rule_crisis brexit_crisis covid_crisis mig_crisis crimea_crisis eurozone $eu_controls _cons) ///
	varlabel(_cons "Constant")

*** Figure A5 online appendix ***
set scheme plottig
coefplot m15 m16 m17 m18, ///
sort keep(mig_crisis eurozone crimea_crisis rule_crisis brexit_crisis covid_crisis wtmean_image par_log)  ///
xline(0) plotlabels("Total infringements" "Formal letters" "Reasoned opinions" "Referrals to ECJ") xlabel(-20(5)5) xscale(range(-20 5))

********************************************************************************
** Robustness ******************************************************************
** non-communication and non-comformity ****************************************
********************************************************************************

eststo clear

eststo: xtpoisson total_inf $eu_controls total_conform eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, vce(robust)
est store m22

eststo: xtpoisson total_inf $eu_controls total_nonc eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log, vce(robust)
est store m23

*** Table A8 online appendix ***
esttab m22 m23, ///
	b(%9.3f) se(%5.3f) star(* 0.10 ** 0.05 *** 0.001) nonumbers ///
	eqlabels(" " " ") ///
	mlabels("Total infringements" "Total infringements") /// 
	varlabel(_cons "Constant" mig_crisis "Migration crisis" crimea_crisis "Crimea crisis" ///
	brexit_crisis "Brexit crisis" eurozone "Eurozone crisis" ///
	covid_crisis "Covid crisis" rule_crisis "Rule of law crisis" wtmean_image "EU image" par_log "Parliament questions" ///
	log_eu "Log of EU years" log_dp "Log of GDP" log_pop "Log of population" EU_trade "Intra-EU trade" ///
	gov "Effectiveness" complaints "Noncompliance" total_conform "Non-conformity"  total_nonc "Non-communication") ///
	order(total_conform total_nonc eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log $eu_controls)

*** Figure A6 online appendix ***
set scheme plottig
coefplot m22 m23, ///
sort keep(total_conform total_nonc eurozone mig_crisis crimea_crisis brexit_crisis covid_crisis rule_crisis wtmean_image par_log)  ///
xline(0) plotlabels("Controlled for non-conformity" "Controlled for non-communication" ) xlabel(-6 3) xscale(range(-6 3))	
